<template>
  <div class="appraise">
    <!-- 上面 -->
    <div class="appraise_top">
      <span class="appraise_top_left">
        <div style="font-size: 30px">4.4</div>
        <div>综合评价</div>
        <div>高于周边商家76.9%</div>
      </span>
      <span class="appraise_top_right">
        <div>
          服务态度
          <van-rate
            v-model="value"
            :size="10"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
          />
          5.5
        </div>
        <div>
          菜品评价
          <van-rate
            v-model="value"
            :size="10"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
          />
          4.9
        </div>
        <div>
          送达时间
          <span>分钟</span>
        </div>
      </span>
    </div>
    <!-- 中间 -->
    <div class="appraise_mid">
      <span
        v-for="(item, index) in commentType"
        :key="item._id"
        @click="comFn(index)"
        :class="{ active: item.unsatisfied }"
      >
        {{ item.name }} ({{ item.count }})
      </span>
    </div>
    <!-- 底部 -->
    <div class="appraise_btm" v-for="item in commentList" :key="item._id">
      <div class="left">
        <img :src="item.avatar" alt="" />
      </div>
      <div class="right">
        <div>{{ item.username }}</div>
        <div>
          <van-rate
            v-model="value"
            :size="10"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
          />
          {{ item.time_spent_desc }}
        </div>
        <div class="rightImg">
          <img
            v-for="(img, index) in item.item_ratings"
            :key="index"
            :src="img.image_hash"
            alt=""
          />
        </div>
        <div class="gg">
          <div
            class="aaa"
            style="border: 1px solid #d1d1d; overflow: hidden"
            v-for="(food, index) in item.item_ratings"
            :key="index"
          >
            {{ food.food_name }}
          </div>
        </div>
      </div>
      <span> {{ item.rated_at }} </span>
    </div>
  </div>
</template>

<script>
import { ratings, getcommentType } from "@/api/elegoodsppraise.js";
export default {
  data() {
    return {
      value: 5,
      getdata: {
        offset: 0,
        limit: 10,
      },
      commentList: [], //商家评论列表
      commentType: [], //评论类型
    };
  },
  methods: {
    // 点击评论类型改变颜色
    comFn(index) {
      this.commentType[index].unsatisfied =
        !this.commentType[index].unsatisfied;
      this.commentType.splice();
      console.log(this.commentType[index].unsatisfied);
    },
  },
  created() {
    // console.log(94, this.$route.query.id);
    // 通过id拿到评论类型数据和评论列表;
    let id = 3590;
    if (this.$route.query.id) {
      id = parseInt(this.$route.query.id);
    }
    console.log(id);
    // console.log(this.getdata);
    ratings(id, this.getdata).then((res) => {
      this.commentList = res.data;
      console.log(this.commentList);
      this.commentList.forEach((item, index) => {
        // console.log(124, item);
        this.commentList[index].avatar =
          "https://fuss10.elemecdn.com/" +
          item.avatar.slice(0, 1) +
          "/" +
          item.avatar.slice(1, 3) +
          "/" +
          item.avatar.slice(3) +
          ".jpeg";
        this.commentList[index].item_ratings.forEach((info, num) => {
          this.commentList[index].item_ratings[num].image_hash =
            "https://fuss10.elemecdn.com/" +
            info.image_hash.slice(0, 1) +
            "/" +
            info.image_hash.slice(1, 3) +
            "/" +
            info.image_hash.slice(3) +
            ".jpeg";
        });

        console.log(item);
      });
    });
    getcommentType(id).then((res) => {
      console.log(res);
      this.commentType = res.data;
    });
  },
};
</script>

<style lang="less" scoped>
.appraise {
  height: calc(100vh - 88px - 45px);
  overflow: scroll;
  padding: 0 5px;
  .appraise_top {
    height: 95px;
    display: flex;
    align-items: center;
    padding: 0 13px;
    background-color: #ffffff;
    .appraise_top_left {
      text-align: center;
    }
    .appraise_top_right {
      div {
        display: flex;
      }
    }
    span {
      flex: 1;
    }
  }
  .appraise_mid {
    box-sizing: border-box;
    height: 168px;
    background-color: #ffffff;
    display: flex;
    flex-wrap: wrap;
    padding: 18px;
    border-top: 15px solid #d1d1d14f;
    border-bottom: 1px solid #b4b4b4;

    span {
      height: 28px;
      line-height: 28px;
      text-align: center;
      border-radius: 6px;
      font-size: 14px;
      color: gray;
      margin-right: 8px;
      background-color: #dfefff;
    }
    .active {
      background-color: #93bfeb;
    }
  }
  .appraise_btm {
    box-sizing: border-box;
    height: 200px;
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #b4b4b4;
    .left {
      width: 20%;
      img {
        width: 77%;
        background-color: #bb8787;
        border-radius: 50%;
      }
    }
    .right {
      width: 55%;
      .rightImg {
        img {
          width: 68px;
          margin-right: 10px;
        }
      }
      .gg {
        display: flex;
        text-align: center;
        .aaa {
          width: 60px;
          height: 33px;
          line-height: 33px;
          color: gray;
          border: 1px solid #b4b4b4;
          margin-top: 10px;
          margin-right: 10px;
        }
      }
    }
    span {
      float: right;
      font-size: 15px;
      color: gray;
    }
  }
}
</style>